{template 'web/common/common'}
{template 'web/land/navbar'}
<link rel="stylesheet" type="text/css" href="../addons/kundian_farm/resource/css/style.css" />
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.css" />
<style>
    .plant-border{width: 260px;height: auto;border: 1px solid #e2e2e2;padding-bottom: 20px;min-height: 240px;box-shadow: 5px 4px 15px 3px #f3ecd9;margin-left: 20px;margin-bottom: 20px;}
    .plant-border .land-name{width: 100%;height: 30px;margin-top: 10px;}
    .land-plant-area{width: 100%;height: 30px;}
    .land-plant-area div{width: 50%;float: left;}
    .dai-seed{width: 100%;line-height: 30px;}
    .dai-seed .label-info{margin-top: 10px;margin-left: 5px}
    .land-date{width: 100%;font-size: 13px;margin-top: 10px;margin-bottom: 20px;}
    .opeartion .btn{padding: 1px 6px;}
    .clear{clear: both;}
</style>
<div class="panel panel-success">

    <div class="panel-heading">
        <h3 class="panel-title">
            种植土地
        </h3>
    </div>
    <div class="ibox-content" style="margin-top: 20px;">
        <form action="{url 'site/entry/send',array('m'=>'kundian_farm','op'=>'send_plant','version_id'=>$_GPC['version_id'])}" id="searchform" method="post">
            <div class="panel panel-info" style="width: 96%;margin-left: 2%;">
                <div class="panel-heading">
                    <h3 class="panel-title"><p>提示：</p>
                        <p>1、点击列表中的土地名称可查看详细信息，以及设置该种植地块的物联网设备号方便用户进行土地操作。</p>
                        <p>2、若没有开启物联网板块可不用设置！</p>
                    </h3>
                </div>
            </div>
            <div class="row" style="padding: 0 15px;">
                <div class="col-sm-2">
                    <select class="form-control" name="lid">
                        <option value="0">土地名称</option>
                        <?php foreach($formLandData as $val){?>
                        <option value="{$val['id']}" <?php if($lid==$val['id']){echo 'selected';}?> >{$val['land_name']}</option>
                        <?php }?>
                    </select>
                </div>
                <div class="col-sm-2">
                    <select class="form-control" name="status">
                        <option value="4" <?php if($status==4){echo 'selected';}?>>种植状态</option>
                        <option value="3" <?php if($status==3){echo 'selected';}?> >未种植</option>
                        <option value="1"  <?php if($status==1){echo 'selected';}?> >已种植</option>
                        <option value="2"  <?php if($status==2){echo 'selected';}?> >已到期</option>
                    </select>
                </div>
                <div class="col-sm-2">
                    <input type="text" class="form-control" placeholder="用户名" name="name" value="{$name}">
                </div>
                <div class="col-sm-2">
                    <button type="submit" class="btn btn-default " style="margin-right:5px;">查询</button>
                    <!--<a class="btn btn-primary" href="{url 'site/entry/send',array('m'=>'kundian_farm','op'=>'edit','version_id'=>$_GPC['version_id'])}">增加</a>-->
                </div>
            </div>
        </form>
    </div>
    <div class="panel-body">
        {loop $list $index $item}
        <div class="col-sm-2 plant-border">
            <div class="land-name">
                <a href="{url 'site/entry/send',array('m'=>'kundian_farm','op'=>'seed_plant_detail','id'=>$item['id'],'version_id'=>$_GPC['version_id'])}" title="点击查看详情">
                    <span class="label label-success">{$item['land_name']}</span>
                </a>
                <span class="label label-warning">{$item['nickname']}({$item['truename']})</span>
            </div>
            <div class="land-plant-area">
                <div class="area-left">总面积：{$item['count']} ㎡</div>
                <div class="area-right">已种植：{$item['seed_area']} ㎡</div>
            </div>
            {if $item['seedData']}
            <div class="dai-seed">
                待播种：
                {loop $item['seedData'] $key $val}
                    <span class="label label-info">{$val['send_name']}</span>
                {/loop}
            </div>
            {/if}
            <div class="land-date">
                <span>期限：{$item['day']}天</span><br>
                <span>到期时间：<?php echo date('Y-m-d H:i:s',$item['exprie_time'])?></span><br>
                {if $item['status']!=2}
                <span class="label label-default exprire_{$item['id']}">{$item['is_expire']}</span>
                {else}
                <span class="label label-danger exprire_{$item['id']}">{$item['is_expire']}</span>
                {/if}
            </div>
            <div class="opeartion">
                {if $item['status']!=2}
                <button type="button" data-id="{$item['id']}" class="btn btn-danger is_expire">土地到期</button>
                {/if}
                <a href="{url 'site/entry/send',array('m'=>'kundian_farm','op'=>'seed_detail','id'=>$item['id'],'version_id'=>$_GPC['version_id'])}">
                    <button class="btn btn-info">种植详情</button>
                </a>
                <a href="{url 'site/entry/send',array('m'=>'kundian_farm','op'=>'status_list','id'=>$item['id'],'version_id'=>$_GPC['version_id'])}">
                    <button class="btn btn-success">状态跟踪</button>
                </a>
            </div>
        </div>
        {/loop}

        <div class="clear"></div>
        <div style="text-align: right;">
            {$pager}
        </div>
    </div>
</div>
<script>
    require(["../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.js"],function(){
        $(function(){
            $(".is_expire").click(function(){
                var that=$(this);
                var id=$(this).attr('data-id');
                swal({
                    title: '提示',
                    text: "确定执行此操作吗?",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '确认',
                    cancelButtonText: '取消',
                }).then(function(isConfirm) {
                    if (isConfirm) {
                        $.ajax({
                            type:"post",
                            url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'seed_expire','version_id'=>$_GPC['version_id'])}",
                            data:{id:id},
                            dataType:'json',
                            success:function(res){
                                if(res.status==1){
                                    swal('操作成功!', '操作成功!', 'success');
                                    $(".exprire_"+id).html("到期")
                                    that.remove();
                                }else{
                                    swal('操作失败!', '操作失败!', 'error');
                                }
                            }
                        })
                    }
                })
            });
        })
    })
</script>